﻿#include "StudentManager.h"

StudentManager::StudentManager() {

	this->m_StuNum = 0;
	//初始化数组指针
	this->s_StuArray = NULL;


}
void StudentManager::Show_Menu()
{
	cout << "````````````````````````````````````````````" << endl << endl;
	cout << "`````````  欢迎使用学生管理系统！ ``````````" << endl << endl;
	cout << "`````````````  0.退出管理程序  `````````````" << endl << endl;
	cout << "`````````````  1.增加学生信息  `````````````" << endl << endl;
	cout << "`````````````  2.显示学生信息  `````````````" << endl << endl;
	cout << "`````````````  3.删除退学学生  `````````````" << endl << endl;
	cout << "`````````````  4.修改学生信息  `````````````" << endl << endl;
	cout << "`````````````  5.查找学生信息  `````````````" << endl << endl;
	cout << "`````````````  6.按照编号排序  `````````````" << endl << endl;
	cout << "`````````````  7.清空所有文档  `````````````" << endl << endl;
	cout << "````````````````````````````````````````````" << endl << endl;
	cout << endl;
}
void StudentManager::exitSystem()
{
	cout << "欢迎下次使用" << endl;
	system("pause");
	exit(0);

}
void StudentManager::Add_Stu() {
	cout << "请输入增加学生数量" << endl;
	int addNum = 0;
	cin >> addNum;
	if (addNum > 0)
	{
		//计算新空间大小
		int newSize = this->m_StuNum + addNum;
		//开辟新空间
		Preson ** newSpace = new Preson * [newSize];
		//将原空间下内容放到新空间下
		if (this->s_StuArray != NULL)
			for (int i = 0; i < this->m_StuNum; i++)
				newSpace[i] = this->s_StuArray[i];
		//输入新数据
		for (int i = 0; i < addNum; i++) {
			int id;
			string name;
			int Cid;
			int dSelect;
			cout << "请输入第" << i + 1 << "个新学生学号" << endl;
			cin >> id;
			cout << "请输入第" << i + 1 << "个新学生姓名" << endl;
			cin >> name;
			cout << "请输入第" << i + 1 << "个新学生班号" << endl;
			cin >> Cid;
			cout << "请选择该学生担任的岗位：" << endl;
			cout << "1、无" << endl;
			cout << "2、班干" << endl;
			cout << "3、班长" << endl;
			cin >> dSelect;
			Preson* student = NULL;
			switch (dSelect)
			{
			case 1://普通学生
				student = new Student(id, name, 1);
				break;
			case 2:
				student = new ClassCadre(id, name, 2);
				break;
			case 3:
				student = new Monitor(id, name, 3);
			default:
				break;
			}
			newSpace[this->m_StuNum + i] = student;
		}
		//释放原有空间
		delete[] this->s_StuArray;
		//更改新空间的指向
		this->s_StuArray = newSpace;
		//更新新的学生人数
		this->m_StuNum = newSize;
		//提示信息
		cout << "成功添加" << addNum << "名学生！" << endl;
	}
	else
	{
		cout << "输入有误" << endl;
	}
	system("pause");
	system("cls");
}
void StudentManager::Show_Stu() {
	for (int i = 0; i < m_StuNum; i++)
	{
		this->s_StuArray[i]->showInfo();
	}
	system("pause");
	system("cls");
}
StudentManager::~StudentManager() {
	if (this->s_StuArray != NULL) {
		delete[] this->s_StuArray;
	}
}
